﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PO_2011.Effect
{
    class Shadow : BitmapFastPixel
    {
        public static Bitmap generate(Bitmap img, string type)
        {
            old_img = img;
            new_img = new Bitmap(img);

            switch (type)
            {
                case "north":
                    shadowNorth(1, 0);
                    break;
                case "east":
                    shadowNorth(0, -1);
                    break;
                case "south":
                    shadowNorth(-1, 0);
                    break;
                case "west":
                    shadowNorth(0, 1);
                    break;
                default:
                    break;
            }

            return new_img;
        }

        private static void shadowNorth(int param1, int param2)
        {
            for (int x = 1; x < old_img.Width - 1; x++)
            {
                for (int y = 1; y < old_img.Height - 1; y++)
                {
                    int[] x1_color = getFastPixel(x - param1, y - param2);
                    int[] x2_color = getFastPixel(x, y);

                    int sum1 = (x1_color[0] + x1_color[1] + x1_color[2]) / 3;
                    int sum2 = (x2_color[0] + x2_color[1] + x2_color[2]) / 3;

                    int wy = sum1 - sum2;

                    if (wy < 0)
                    {
                        new_img.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                    }
                    else
                    {
                        new_img.SetPixel(x, y, Color.FromArgb(wy, 0, 0, 0));
                    }
                }
            }
        }

    }
}
